<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Account
 *
 * @author bom
 */
class Account extends Zend_Db_Table_Abstract {

    //put your code here
    protected $_name = 'user_account';
    protected $_primary = 'user_id';
    //protected $_dependentTables = array('country');

    /* protected $_referenceMap    = array(
      'city_country' => array(
      'columns'           => 'country_id',
      'refTableClass'     => 'Country',
      'refColumns'        => 'id'
      )
      ); */
    public function isUsernameUsed($username){
        $select = $this->select()->where("username=?",$username);
        $rowSet = $this->fetchRow($select);
        if($rowSet->user_id){
            return true;
        }else{
            return false;
        }
    }
    public function isEmailUsed($email){
        $select = $this->select()->where("email=?",$email);
        $rowSet = $this->fetchRow($select);
        if($rowSet->user_id){
            return true;
        }else{
            return false;
        }
    }
    public function getUserByUsername($username){
		$userRowset = $this->fetchAll($this->select()->where('username = ?',$username));
		$user = $userRowset->current();
		return $user;
	}
	public function getUserByEmail($email){
		$userRowset = $this->fetchAll($this->select()->where('email = ?',$email));
		$user = $userRowset->current();
		return $user;
	}
	public function getUserById($id){
		$userRowset = $this->fetchAll($this->select()->where('user_id = ?',$id));
		$user = $userRowset->current();
		return $user;
	}
	public function changePassword($id, $pass)
	{
		$this->update(array("password" => $pass), "user_id = $id");
	}
}

?>
